/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package database;

import java.sql.Date;
import java.sql.SQLException;
import java.sql.Time;
import java.util.ArrayList;

/**
 *
 * @author vincent
 */
public class TestVincent {

    public static void main(String argv[]) throws SQLException, InterruptedException {
        DataService ds = DataService.getInstance();
        /*Profiles*/
        Profile vincent = new Profile("Vincent", "Baena", "123");
        Profile mariam = new Profile("Mariam", "Kadoura", "123");
        Profile jacques = new Profile("Jacques", "Chirac", "01");
        ds.insertProfile(vincent);
        ds.insertProfile(mariam);
        ds.insertProfile(jacques);

        /*Friendship*/
        ds.insertPendingFriendship(vincent, mariam);
        ds.insertPendingFriendship(jacques, mariam);
        ds.insertPendingFriendship(vincent, jacques);

        /*Messages*/
        Message vincentToMariam = new Message(vincent, mariam, "Coucou", true);
        //Thread.sleep(1000);
        Message mariamToVincent = new Message(mariam, vincent, "ça va ?", true);
       // Thread.sleep(1000);
        Message VincentToMariam2 = new Message(vincent, mariam, "Bien et toi ?");
        //Thread.sleep(1000);
        Message mariamToVincent2 = new Message(mariam, vincent, "Je vais bien");
        //Thread.sleep(1000);
        Message vincentToJacques = new Message(vincent, jacques, "Salut Jacques");
        //Thread.sleep(1000);
        Message jacquesToVincent = new Message(jacques, vincent, "Salut Vincent, c'est jacques");
        //Thread.sleep(1000);
        Message mariamToJacques = new Message(mariam, jacques, "Salut jacques c'est mariam");
       // Thread.sleep(1000);
        Message jacquesTomariam = new Message(jacques, mariam, "Salut Mariam c'est jacques");

        File file1 = new File("hello.txt", vincent, mariam);
        File file2 = new File("ump.jpg", vincent, jacques);
        File file3 = new File("fichiertropvieux.jpg", vincent, mariam, new Date(1220227200L), new Time(0L));

        ds.acceptFriendship(mariam, vincent);
        
        ds.insertMessage(vincentToMariam);
        ds.insertMessage(mariamToVincent);
        ds.insertMessage(VincentToMariam2);
        ds.insertMessage(mariamToVincent2);
        ds.insertMessage(vincentToJacques);
        ds.insertMessage(jacquesToVincent);
        ds.insertMessage(mariamToJacques);
        ds.insertMessage(jacquesTomariam);

        System.err.println(ds.insertFile(file1));
        ds.insertFile(file2);
        //ds.deleteFile(file1);
        ds.insertFile(file3);
        ds.setFileDownloaded(file3);
        System.err.println("List de tous les fichiers " + ds.getAllFiles(mariam));
        System.err.println("List de tous les fichiers non téléchargés " + ds.getNotDownloadedFiles(mariam));
        System.out.println("Files to remove :" + ds.getOldFiles());
        System.err.println("FileID du ficher trop vieux :" + ds.getFileID(file3));
        /*Test conversation*/
        ArrayList<Message> conversationMariamVincent = ds.getUndeliveredConversation(mariam, vincent);

        for (Message current : conversationMariamVincent) {
            System.out.println(current);
        }
        
        ds.setViewedConversation(mariam, vincent);
        
        conversationMariamVincent = ds.getUndeliveredConversation(mariam, vincent);

        System.out.println("Test viewed messages");
        for (Message current : conversationMariamVincent) {
            System.out.println(current);
        }
        
        /*getProfile from login*/
        Profile p = ds.getProfile("mariam.kadoura");
        System.out.println(p);
        ds.setAdmin(p, true);
        /*Message m = new Message(p1,p2, "Ceci est un message");
        
         System.err.println(ds.insertFriendship(p1, p2));
         System.out.println("Message de "+m.getSender().getFirstName()+" à "+m.getReceiver().getLastName());
         System.out.println("Envoyé à " +m.getTimeMsg()+" le "+m.getDateMsg());
         System.out.println(m.getText());
        
         //System.out.println(ds.insertMessage(m));
         ArrayList<String> contacts = ds.getContactList(p2);
        
         System.out.println("Liste de Mariam");
         for(String current : contacts){
         System.out.println(current);
         }*/
        ds.setStatus(mariam, Profile.Status.BUSY);
        ds.setStatus(vincent, Profile.Status.CONNECTED);
        ds.setStatus(jacques, Profile.Status.AWAY);
    }
}
